﻿using System;
using Microsoft.Practices.Unity;
using SLNGP.Core.Individuals;

namespace SLNGP.Core.Fitness
{
    public class SingleIndivdualFitnessFunction<T> : FitnessFunction, ISingleFitnessFunction<T>
    {
        [InjectionConstructor]
        public SingleIndivdualFitnessFunction()
        {
        }

        public SingleIndivdualFitnessFunction(Func<IIndividual, T> evaluateFunction)
        {
            this.EvaluateFunction = evaluateFunction;
        }

        public Func<IIndividual, T> EvaluateFunction { get; set; }


        public T Evaluate(IIndividual individual)
        {
            return EvaluateFunction(individual);
        }

        public override void Evaluate(IGeneration generationToEvaluate)
        {
            foreach (IIndividual individualToEvaluate in generationToEvaluate)
            {
                // TODO: document fitness changes if those occur
                individualToEvaluate.Fitness = Evaluate(individualToEvaluate);
            }

        }
    }
}